package com.qt.stream;

import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Stream;

public class StreamDemo02 {
    public static void main(String[] args) {

        ArrayList<String> strList1 = new ArrayList<>();
        ArrayList<String> strList2 =  new ArrayList<>();
        Collections.addAll(strList1, "张无忌", "周芷若", "赵敏", "张强", "张三丰");
        Collections.addAll(strList1,  "张强", "张三丰");
        strList1.stream().filter(new Predicate<String>() {
            @Override
            public boolean test(String s) {
                return s.startsWith("张");
            }
        }).forEach(s -> System.out.println(s));

        System.out.println("============");

        //获取 "赵敏", "张强"
        strList1.stream().limit(4).skip(2).forEach(s -> System.out.println(s));
        strList1.stream().skip(2).limit(2).forEach(s -> System.out.println(s));

        System.out.println("============");
        Stream.concat(strList1.stream(),strList2.stream()).forEach(s -> System.out.println(s));

        System.out.println("============");
        ArrayList<String> strList3 = new ArrayList<>();
        Collections.addAll(strList3, "张无忌-18", "周芷若-19", "赵敏-20", "张强-21", "张三丰-22");

        strList3.stream().map(new Function<String, Integer>() {
            @Override
            public Integer apply(String s) {
                String[] split = s.split("-");
                String value = split[1];
                return Integer.parseInt(value);
            }
        }).forEach(s -> System.out.println(s));

        strList3.stream().map(s-> {
                String[] split = s.split("-");
                String value = split[1];
                return Integer.parseInt(value);
            }
        ).forEach(s -> System.out.println(s));





    }

}
